﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TechTalk.SpecFlow;
using System.Drawing.Imaging;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using CERT.PageLibrary.Base;


namespace CERT.AcceptanceTests
{
    [Binding]
    public class LoginExternalSteps : TestFixtureBase
    {
        // For additional details on SpecFlow step definitions see http://go.specflow.org/doc-stepdef
        //code taken from http://www.infoq.com/articles/Spec-Flow
        //http://anoopjshetty.wordpress.com/2012/04/19/behaviour-driven-development-bdd-in-net-using-specflow-selenium-and-nunit/


        [Given(@"I am at the cert login page")]
        public void GivenIAmAtTheCertLoginPage()
        {
            var info = ScenarioContext.Current.ScenarioInfo;
            Assert.AreEqual("Getting to the facebook login", info.Title);
            if (CurrentDriver == null)
                CurrentDriver = (RemoteWebDriver)ScenarioContext.Current["CurrentDriver"];
            CurrentDriver.Navigate().GoToUrl("http://localhost:6014/");

            Assert.AreEqual(2, CurrentDriver.FindElementsByName("UserName").Count);
        }

        [When(@"I click the facebook button")]
        public void WhenIClickTheFacebookButton()
        {
            if (CurrentDriver == null)
                CurrentDriver = (RemoteWebDriver)ScenarioContext.Current["CurrentDriver"];
            var facebook = CurrentDriver.FindElementByName("provider");

            if (facebook == null)
                Assert.Fail("Expected to find a button with the value of 'Login'.");

            facebook.Click();
        }

        [Then(@"I should be at the facebook login page")]
        public void ThenIShouldBeAtTheFacebookLoginPage()
        {
            var facebook = CurrentDriver.FindElementById("loginbutton");

            if (facebook == null)
                Assert.Fail("Expected to find a button with the value of 'login button'.");
            Assert.AreEqual("facebook", CurrentDriver.Title.ToLower());
        }

        //[Given(@"I am at the facebook login page")]
        //public void GivenIAmAtTheFacebookLoginPage()
        //{
        //    //   ScenarioContext.Current.Pending();
        //}

        //[When(@"I fill in the facebook login form")]
        //public void WhenIFillInTheFacebookLoginForm(Table table)
        //{
        //    //   ScenarioContext.Current.Pending();
        //}

    }
}
